﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;


namespace desktop.Igrica
{
    class Slovo
    {
        private static Random _rand = new Random();

        private Font _font, _deathFont;
        private Brush _brush, _deathBrush;

        private float _speed;
        private int _anim = 0;


        private Slovo(char karakter, float velicina, float x, float y)
        {
            X = x;
            Y = y;
            Karakter = karakter;

            _speed = 2.0f + (float)_rand.Next(11) / 10;
           
            _font = new Font("Comic Sans MS", velicina);
            _brush = new SolidBrush(Color.FromArgb(255, 0, 0, 0));

            _deathFont = new Font("Comic Sans MS", velicina + 15);
            _deathBrush = new SolidBrush(Color.FromArgb(255, 255, 0, 0));

            IsDead = false;
        }

        public static Slovo NovoSlovo(int maxWidth)
        {
            return new Slovo(Convert.ToChar(65 + _rand.Next(26)),  // Karakter
                             15 + _rand.Next(30),                  // Velicina slova
                             _rand.Next(maxWidth - 50),            // x pozicija 
                             -(20 + _rand.Next(30)));              // y pozicija
        }


        public float X {
            get;
            private set;
        }

        public float Y {
            get;
            private set;
        }

        public char Karakter {
            get;
            private set;
        }

        public bool IsDead
        {
            get;
            private set;
        }

        public void animate_death()
        {
            _anim = 1;
        }

        public void Iscrtaj(Graphics g)
        {
            if (_anim == 0)
            {
                g.DrawString(Karakter.ToString(), _font, _brush, 10 + X, Y);
                return;
            }

            Font f = _font;
            Brush b = _brush;

            if ( _anim < 3)
            {
                f = _deathFont;
                b = _deathBrush;
                _anim++;
            }
            else
                if (_anim < 5)
                {
                    _anim++;
                }
                else
                    if (_anim == 5)
                        IsDead = true;

            g.DrawString(Karakter.ToString(), f, b, 10 + X - 10, Y - 10);
        }

        public void Update()
        {
            Y += _speed;
        }

    }

}
